package com.example.manager.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class R<T>{

    private int code = 200;//定义响应的状态码

    private String msg = "success";//响应的信息描述

    private T data;//响应的数据

    public R(T data){
        this.data = data;
    }

    public R(String msg){
        this.msg = msg;
    }

    public R(int code){
        this.code = code;
    }

    public R(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public R(int code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public R(int code, T data){
        this.code = code;
        this.data = data;
    }
    public static <T> R<T> success(T data){
        return new R<>(data);
    }
    public static <T> R<T> success(){
        return new R<>();
    }
    public static <T> R<T> success(String msg){
        return new R<>(msg);
    }

    public static <T> R<T> success(int code){
        return new R<>(code);
    }

    public static <T> R<T> success(int code,String msg){
        return new R<>(code,msg);
    }
    public static <T> R<T> success(int code,String msg,T data){
        return new R<>(code,msg,data);
    }



    public static <T> R<T> fail(T data){
        return new R<>(500,"fail",data);
    }
    public static <T> R<T> fail(){
        return new R<>(500,"fail");
    }
    public static <T> R<T> fail(String msg){
        return new R<>(500,msg);
    }

    public static <T> R<T> fail(int code){
        return new R<>(code,"fail");
    }

    public static <T> R<T> fail(int code,String msg){
        return new R<>(code,msg);
    }
    public static <T> R<T> fail(int code,String msg,T data){
        return new R<>(code,msg,data);
    }


}
